#include <bits/stdc++.h>
using namespace std;
struct node{
    int lw, ll, rw, rr;
    node *l, *r;
    node():ll(0), rr(0), lw(0), rw(0), l(nullptr), r(nullptr){}
};
bool bal;
int build(node *r){
    cin >> r->lw >> r->ll >> r->rw >> r->rr;
    if(!r->lw){
        r->l = new node;
        r->lw = build(r->l);
    }
    if(!r->rw){
        r->r = new node;
        r->rw = build(r->r);
    }
    if(r->lw * r->ll != r->rr * r->rw) bal = false;
    return r->lw + r->rw;
}

void del(node *r){
    if(r->l) del(r->l);
    if(r->r) del(r->r);
    delete(r);
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        bal = true;
        node *root = new node;
        build(root);
        if(bal) cout << "YES\n"; else cout << "NO\n";
        if(T) cout << "\n";
        del(root);
    }
    return 0;
}